<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Goods extends Model
{
    // 表名
    protected $connection = 'database.cheat';
    protected $table = 'goods';
    use SoftDelete;
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'goods_verify_text',
        'goods_commend_text',
        'source_text',
        'status_text',
    ];
    

    
    public function getGoodsVerifyList()
    {
        return ['1' => __('Goods_verify 1'),'2' => __('Goods_verify 2'),'3' => __('Goods_verify 3')];
    }
    public function getStatusList()
    {
        return ['1' => __('Status 1'),'2' => __('Status 2'),'3' => __('Status 3')];
    }
    public function getGoodsCommendList()
    {
        return ['1' => __('Goods_commend 1'),'2' => __('Goods_commend 2')];
    }     

    public function getSourceList()
    {
        return ['1' => __('Source 1'),'2' => __('Source 2')];
    }     


    public function getGoodsVerifyTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['goods_verify']) ? $data['goods_verify'] : '');
        $list = $this->getGoodsVerifyList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getGoodsCommendTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['goods_commend']) ? $data['goods_commend'] : '');
        $list = $this->getGoodsCommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSourceTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['source']) ? $data['source'] : '');
        $list = $this->getSourceList();
        return isset($list[$value]) ? $list[$value] : '';
    }

#关联分类id
public function classes(){
        return $this->belongsTo('Classes','classes_id','id')->setEagerlyType(0);
}


}
